/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package testdockerdb.carcontroller.controllers;

import com.google.gson.Gson;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import testdockerdb.carcontroller.models.CarPos;
import testdockerdb.carcontroller.models.CarPosResult;
import testdockerdb.carcontroller.models.Coordinate;
import testdockerdb.carcontroller.services.DbOperation;

/**
 *
 * @author wuhao
 */
@RestController
public class CarPosController {

        DbOperation dbOpera = null;

        public CarPosController() {
                dbOpera = new DbOperation();
        }

        @CrossOrigin
        @RequestMapping("/geocoding")
        String GetPos(@RequestParam(value = "vin", required = true) String vin) {
                System.out.println("geocoding...");
                String jsonInString = "";
                // jsonInString = GetSampleData();

                Gson gson = new Gson();
                jsonInString = gson.toJson(dbOpera.GetCurPos(vin));
                return jsonInString;
        }

        String GetSampleData() {
                Gson gson = new Gson();

                Coordinate c = new Coordinate();
                c.setLon(114.28);
                c.setLat(30.59);

                CarPos cp = new CarPos();
                cp.setLocation(c);
                cp.setRate(120.35);
                cp.setStat("100");

                CarPosResult cpr = new CarPosResult();
                cpr.setResults(cp);
                cpr.setRet("0");

                String jsonInString = gson.toJson(cpr);

                return jsonInString;
        }

}
